package com.myapp.ruyixing.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.myapp.ruyixing.R;
import com.myapp.ruyixing.http.RYHttpClient;
import com.myapp.ruyixing.http.RYHttpResponseHandler;
import com.myapp.ruyixing.ui.widget.TitleBar;

public class FeedbackActivity extends BaseActivity {

	private RYHttpResponseHandler mHandler = new RYHttpResponseHandler() {

		@Override
		public void onSuccess(Object o) {
			Toast.makeText(getApplicationContext(), "提交成功，谢谢",
					Toast.LENGTH_LONG).show();
			finish();
		}

		@Override
		public void onFailure(Throwable throwable) {
			Toast.makeText(getApplicationContext(), "提交失败", Toast.LENGTH_LONG)
					.show();

		}
	};

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);

		setContentView(R.layout.activity_feedback);

		findViewById(R.id.submit).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String content = ((TextView) findViewById(R.id.content))
						.getText().toString();
				String phone = ((TextView) findViewById(R.id.phone)).getText()
						.toString();

				if (!TextUtils.isEmpty(content)) {
					RYHttpClient.submitFeedback(getApplicationContext(),
							mHandler, content, phone);
				}
			}
		});

		((TitleBar) findViewById(R.id.title_bar))
				.setOnIconClickedListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						finish();
					}
				});
	}
}
